package com.nkzy.bigeventback.service.impl;

import com.nkzy.bigeventback.entity.Category;
import com.nkzy.bigeventback.mapper.CategoryMapper;
import com.nkzy.bigeventback.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper cm;

    @Override
    public void addCategory(Category category) {
        category.setCreateTime(LocalDateTime.now());//获取当前时间添加到对象中
        category.setUpdateTime(LocalDateTime.now());
        category.setCreateUser( 1 );
        cm.insertCategory(category);
    }

    @Override
    public List<Category> findAllCategory() {
        return cm.selectAllCategory(1);//id为1的用户查询的文章分类
    }

    @Override
    public void modifyCategory(Category category) {
        //根据id查询category
        Category categoryDB = cm.selectCategoryById(category.getId());
        //查询后的对象，使用set方法修改属性
        categoryDB.setCategoryName(category.getCategoryName());
        categoryDB.setCategoryAlias(category.getCategoryAlias());
        categoryDB.setUpdateTime(LocalDateTime.now());
        cm.updateCategory(categoryDB);

    }
    @Override
    public void removeCategory(Integer id) {
        cm.remove(id);
        System.out.println("删除成功");
    }
}
